package cn.ipanel.bigdata.job.basic

import cn.ipanel.bigdata.boot.Session
import cn.ipanel.bigdata.boot.config.Configuration
import cn.ipanel.bigdata.boot.logger.Logger

/**
 * @author lzz
 * @environment IntelliJ IDEA 2020.3.1
 * @projectName bigdata_shanxi
 * @date 2023/06/20 15:33
 * @description: 用于 redis 字段补充 字段补充
 */
trait RedisSupplier extends Session {

  /**
   * spark变量的惰性加载机制，此特征应该立即加载，否则其他使用spark的地方先生效会导致这里的配置无效
   */
  val newConf = {
    Logger.I("spark新配置：" + spark.conf.getAll.toString())
    Logger.I("spark redis 配置， host: " + spark.conf.get("spark.redis.host")
      + "\nport: " + spark.conf.get("spark.redis.port")
      + "\nauth: " + spark.conf.get("spark.redis.auth")
      + "\ndb: " + spark.conf.get("spark.redis.db"))
  }

  override def optCostumerConf: Map[String, String] = {
    Map("spark.redis.host" -> Configuration.getDatabase("redis_online").host
      , "spark.redis.port" -> Configuration.getDatabase("redis_online").port
      , "spark.redis.auth" -> Configuration.getDatabase("redis_online").password
      , "spark.redis.db" -> Configuration.getDatabase("redis_online").db)
  }

}
